package com.xm.xmds1705083.service.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.util.ErrorCode;
import com.xm.xm.util.ValidateUtils;
import com.xm.xmds1705083.service.mapper.DuoduoPaymentRecordsMapper;
import com.xm.xmds1705083.service.model.DuoduoPaymentRecords;
import com.xm.xmds1705083.service.model.SocketEntity;
import com.xm.xmds1705083.service.service.DuoduoPaymentRecordsService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 杭州新苗网络科技有限公司
 * @author meihf
 * @date 2017/06/15
 * @description
*/ 
@Service("duoduoPaymentRecordsService")
public class DuoduoPaymentRecordsServiceImpl extends ServiceImpl<DuoduoPaymentRecordsMapper,DuoduoPaymentRecords> implements DuoduoPaymentRecordsService {
    static Logger logger = LoggerFactory.getLogger(DuoduoPaymentRecordsServiceImpl.class);

    @Autowired
    DuoduoPaymentRecordsMapper duoduoPaymentRecordsMapper;


    /**
     * 现金缴费记录
     * @param entity
     * @return
     */
    @Override
    public ResultDto payInfoSyn(SocketEntity entity) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = new JSONObject();
        try {
            if (!filed.has("recordID") || !filed.has("datasrc")
                    ||!filed.has("inputType") || !filed.has("mediaNo")
                    ||!filed.has("inputTime") || !filed.has("outputTime")
                    ||!filed.has("parType")||!filed.has("amount")){
                logger.info(ErrorCode.E10011);
            }else{
                JSONObject params = JSONObject.fromObject(entity.getParam());
                String recordId = params.getString("recordID");
                String datasrc = params.getString("datasrc");
                String inputType = params.getString("inputType");
                String mediaNo = params.getString("mediaNo");
                String payType = params.getString("payType");
                int amount = params.getInt("amount");
                String enterStatus = params.getString("enterStatus");
                String inputTime = params.getString("inputTime");
                String outputTime = params.getString("outputTime");
                int parkCount = params.getInt("parkCount");
                DuoduoPaymentRecords paymentRecords = new DuoduoPaymentRecords();
                paymentRecords.setAmount((double) amount);
                paymentRecords.setInputTime(inputTime);
                paymentRecords.setOutputTime(outputTime);
                paymentRecords.setMediaNo(mediaNo);
                paymentRecords.setParkCount(parkCount);
                paymentRecords.setPayType(Integer.parseInt(payType));
                int result = duoduoPaymentRecordsMapper.insert(paymentRecords);
                if (ValidateUtils.isGreaterThan0(result)){
                    filed.put("recordID",recordId);
                    filed.put("result","00");
                    filed.put("rsv1","");
                    filed.put("rsv2","");
                }else {
                    filed.put("recordID",recordId);
                    filed.put("result","01");
                    filed.put("rsv1","");
                    filed.put("rsv2","");
                }
            }
            resultDto.setData(filed);
        }catch (RuntimeException e ){
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }
}

